#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e3+10, INF = 0x3f3f3f3f;
typedef pair<int, int> pii;
pii W[maxn];
int n, g[maxn];

int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    cin >> n;
    int ans = 0;
    memset(g, INF, sizeof(g));
    for (int i = 0; i < n; ++i) {
        cin >> W[i].first >> W[i].second;
    }

    sort(W, W+n, greater<>());
    for (int i = 0; i < n; ++i) {
        int k = lower_bound(g+1, g+1+n, W[i].second) - g;
        ans = max(ans, k);
        g[k] = W[i].second;
    }
    cout << ans;
    return 0;
}